Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
temperature=0.2, # Lower temperature for less randomness
|
| 14 |
-
repetition_penalty=1.5, # Penalize repetitive tokens
|
| 15 |
-
no_repeat_ngram_size=2 # Prevent repeating 2-word sequences
|
| 16 |
-
)
|
| 17 |
-
return generated[0]['generated_text']
|
| 18 |
|
| 19 |
-
# Create
|
| 20 |
iface = gr.Interface(
|
| 21 |
-
fn=
|
| 22 |
inputs="text",
|
| 23 |
outputs="text",
|
| 24 |
-
title="
|
| 25 |
-
description="
|
| 26 |
)
|
| 27 |
|
| 28 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load a question-answering model instead of a text generator
|
| 5 |
+
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 6 |
|
| 7 |
+
def get_answer(question):
|
| 8 |
+
context = """
|
| 9 |
+
London is the capital of the United Kingdom. The UK consists of England, Scotland, Wales, and Northern Ireland.
|
| 10 |
+
"""
|
| 11 |
+
answer = qa_pipeline(question=question, context=context)
|
| 12 |
+
return answer["answer"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Create Gradio Interface
|
| 15 |
iface = gr.Interface(
|
| 16 |
+
fn=get_answer,
|
| 17 |
inputs="text",
|
| 18 |
outputs="text",
|
| 19 |
+
title="Ask Any Question",
|
| 20 |
+
description="Ask factual questions and get precise answers."
|
| 21 |
)
|
| 22 |
|
| 23 |
iface.launch()
|