Update main.py
Browse files
main.py
CHANGED
@@ -1,32 +1,21 @@
|
|
1 |
-
|
2 |
-
from fastapi.staticfiles import StaticFiles
|
3 |
-
from fastapi.responses import FileResponse
|
4 |
-
|
5 |
from transformers import pipeline
|
6 |
-
|
7 |
import gradio as gr
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
pipe_flan = pipeline("text-generation", model="gpt2")
|
12 |
|
13 |
-
|
14 |
-
def
|
15 |
output = pipe_flan(input, max_length=130, num_return_sequences=1)
|
16 |
-
#return {"output": output[0]["generated_text"]}
|
17 |
return output[0]["generated_text"]
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
#@app.get("/")
|
22 |
-
#def index() -> FileResponse:
|
23 |
-
# return FileResponse(path="/app/static/index.html", media_type="text/html")
|
24 |
-
|
25 |
demo = gr.Interface(
|
26 |
-
fn=
|
27 |
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
|
28 |
outputs=gr.outputs.Textbox(label="Generated Text")
|
29 |
)
|
30 |
|
31 |
-
|
32 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
1 |
+
#Imporing required libraries
|
|
|
|
|
|
|
2 |
from transformers import pipeline
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
+
# Defining the pipeline and the model
|
|
|
6 |
pipe_flan = pipeline("text-generation", model="gpt2")
|
7 |
|
8 |
+
# Text generation
|
9 |
+
def generator(input):
|
10 |
output = pipe_flan(input, max_length=130, num_return_sequences=1)
|
|
|
11 |
return output[0]["generated_text"]
|
12 |
|
13 |
+
# Creating the Gradio Interface
|
|
|
|
|
|
|
|
|
|
|
14 |
demo = gr.Interface(
|
15 |
+
fn=generator,
|
16 |
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
|
17 |
outputs=gr.outputs.Textbox(label="Generated Text")
|
18 |
)
|
19 |
|
20 |
+
# Lauching the Gradio Interface
|
21 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|