ambrosfitz commited on
Commit
f7c8641
·
verified ·
1 Parent(s): 720f1cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import torch
3
  from transformers import AutoModelForSeq2SeqLM, T5Tokenizer
 
4
 
5
  # Load the model and tokenizer from Hugging Face
6
  model_name = "ambrosfitz/history-qa-t5-base"
@@ -41,15 +42,27 @@ def generate_qa(text, max_length=512):
41
  else:
42
  return "Unable to generate a proper question and answer. Please try again with a different input."
43
 
44
- # Define the Gradio interface
45
- iface = gr.Interface(
46
- fn=generate_qa,
47
- inputs=gr.Textbox(lines=5, label="Enter historical text"),
48
- outputs=gr.Textbox(label="Generated Q&A"),
49
- title="History Q&A Generator",
50
- description="Enter a piece of historical text, and the model will generate a related question, answer options, correct answer, and explanation."
51
- )
52
 
53
- # Launch the app
54
- if __name__ == "__main__":
55
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import torch
3
  from transformers import AutoModelForSeq2SeqLM, T5Tokenizer
4
+ import time
5
 
6
  # Load the model and tokenizer from Hugging Face
7
  model_name = "ambrosfitz/history-qa-t5-base"
 
42
  else:
43
  return "Unable to generate a proper question and answer. Please try again with a different input."
44
 
45
+ def slow_qa(message, history):
46
+ full_response = generate_qa(message)
47
+ for i in range(len(full_response)):
48
+ time.sleep(0.01) # Adjust this value to control the speed of the response
49
+ yield full_response[:i+1]
 
 
 
50
 
51
+ # Create and launch the Gradio interface
52
+ gr.ChatInterface(
53
+ slow_qa,
54
+ chatbot=gr.Chatbot(height=500),
55
+ textbox=gr.Textbox(placeholder="Enter historical text here...", container=False, scale=7),
56
+ title="History Q&A Generator",
57
+ description="Enter a piece of historical text, and the model will generate a related question, answer options, correct answer, and explanation.",
58
+ theme="soft",
59
+ examples=[
60
+ "The American Revolution was a colonial revolt that took place between 1765 and 1783.",
61
+ "World War II was a global conflict that lasted from 1939 to 1945, involving many of the world's nations.",
62
+ "The Renaissance was a period of cultural, artistic, political, and economic revival following the Middle Ages."
63
+ ],
64
+ cache_examples=False,
65
+ retry_btn="Regenerate",
66
+ undo_btn="Remove last",
67
+ clear_btn="Clear",
68
+ ).launch()