AbdulMoid commited on
Commit
33c200c
1 Parent(s): 28f6d2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -22
app.py CHANGED
@@ -1,35 +1,17 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- from fastapi import FastAPI
4
- from pydantic import BaseModel
5
- import uvicorn
6
 
7
  # Load the model
8
  model_name = "nvidia/Llama3-ChatQA-1.5-8B"
9
  qa_pipeline = pipeline("text-generation", model=model_name)
10
 
11
- # FastAPI app
12
- app = FastAPI()
13
-
14
- class Query(BaseModel):
15
- inputs: str
16
-
17
- @app.post("/predict")
18
- async def predict(query: Query):
19
- response = qa_pipeline(query.inputs, max_length=250)
20
- return {"generated_text": response[0]["generated_text"]}
21
-
22
- # Gradio app
23
  def generate_answer(question):
 
24
  response = qa_pipeline(question, max_length=250)
25
  return response[0]["generated_text"]
26
 
 
27
  iface = gr.Interface(fn=generate_answer, inputs="text", outputs="text", title="Llama3 ChatQA")
28
 
29
- # Mount Gradio app to FastAPI
30
- @app.get("/")
31
- async def gradio_app():
32
- return gr.mount_gradio_app(app, iface)
33
-
34
- if __name__ == "__main__":
35
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
  import gradio as gr
2
  from transformers import pipeline
 
 
 
3
 
4
  # Load the model
5
  model_name = "nvidia/Llama3-ChatQA-1.5-8B"
6
  qa_pipeline = pipeline("text-generation", model=model_name)
7
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def generate_answer(question):
9
+ # Generate the answer using the model
10
  response = qa_pipeline(question, max_length=250)
11
  return response[0]["generated_text"]
12
 
13
+ # Create the Gradio interface
14
  iface = gr.Interface(fn=generate_answer, inputs="text", outputs="text", title="Llama3 ChatQA")
15
 
16
+ # Launch the interface and set share=True to create a public URL
17
+ iface.launch(share=True)