Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
print("Loading AI...")
|
| 6 |
-
generator = pipeline('text-generation', model='gpt2')
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
#this tells the AI to generate an answer
|
| 11 |
-
result = generator(question, max_length= 100, num_return_sequences=1)
|
| 12 |
-
answer = result[0]
|
| 13 |
-
['generated_text']
|
| 14 |
-
#we return the answer to the user return answer
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
MODEL_NAME = "gpt2"
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
print(f"Loading{MODEL_NAME}...")
|
| 7 |
+
generator = pipeline('text-generation', model = MODEL_NAME)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
def ask_brain(question):
|
| 10 |
+
result = generator(question, max_length = 100, num_return_sequences=1)
|
| 11 |
+
answer= result[0]
|
| 12 |
+
['generated_text']
|
| 13 |
+
return answer.replace(question, "").strip()
|
| 14 |
+
|
| 15 |
+
iface = gr.Interface(fn=ask_brain, inputs="text", outputs="text"
|
| 16 |
+
)
|
| 17 |
+
iface.launch()
|