ekinnk commited on
Commit
182ac61
·
1 Parent(s): a2d90e8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -18
main.py CHANGED
@@ -1,32 +1,21 @@
1
- from fastapi import FastAPI
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
- #app = FastAPI()
10
-
11
  pipe_flan = pipeline("text-generation", model="gpt2")
12
 
13
- #@app.get("/infer_gpt2")
14
- def gpt2(input):
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
- #app.mount("/", StaticFiles(directory="static", html=True), name="static")
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=gpt2,
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)