Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
|
| 4 |
+
# Load your model
|
| 5 |
+
model_name = "CJHauser/PrisimAI-t5"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
def answer_question(context, question):
|
| 10 |
+
input_text = f"question: {question} context: {context}"
|
| 11 |
+
inputs = tokenizer.encode(input_text, return_tensors="pt", truncation=True)
|
| 12 |
+
outputs = model.generate(inputs, max_length=128)
|
| 13 |
+
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
+
return answer
|
| 15 |
+
|
| 16 |
+
# Gradio UI
|
| 17 |
+
with gr.Blocks() as demo:
|
| 18 |
+
gr.Markdown("# π€ PrisimAI Q&A\nAsk questions based on a given context.")
|
| 19 |
+
|
| 20 |
+
with gr.Row():
|
| 21 |
+
context = gr.Textbox(label="Context", placeholder="Paste your reference text here...", lines=8)
|
| 22 |
+
|
| 23 |
+
question = gr.Textbox(label="Your Question", placeholder="What do you want to know?")
|
| 24 |
+
answer = gr.Textbox(label="Answer", interactive=False)
|
| 25 |
+
|
| 26 |
+
btn = gr.Button("Get Answer")
|
| 27 |
+
btn.click(fn=answer_question, inputs=[context, question], outputs=answer)
|
| 28 |
+
|
| 29 |
+
demo.launch()
|