Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Instruction-following model
|
| 5 |
+
assistant = pipeline(
|
| 6 |
+
"text2text-generation",
|
| 7 |
+
model="google/flan-t5-base"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
def ai_assistant(question):
|
| 11 |
+
prompt = f"Answer clearly and in detail:\n{question}"
|
| 12 |
+
result = assistant(
|
| 13 |
+
prompt,
|
| 14 |
+
max_new_tokens=400,
|
| 15 |
+
temperature=0.3
|
| 16 |
+
)
|
| 17 |
+
return result[0]["generated_text"]
|
| 18 |
+
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
gr.Markdown("# 🤖 AI Assistant (Proper Answers)")
|
| 21 |
+
gr.Markdown("This AI understands instructions and gives clean answers.")
|
| 22 |
+
|
| 23 |
+
question = gr.Textbox(
|
| 24 |
+
label="Your Question",
|
| 25 |
+
placeholder="e.g. Write complete notes on Quaid-e-Azam"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
answer = gr.Textbox(
|
| 29 |
+
label="AI Answer",
|
| 30 |
+
lines=10
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
btn = gr.Button("Ask AI")
|
| 34 |
+
btn.click(ai_assistant, question, answer)
|
| 35 |
+
|
| 36 |
+
demo.launch()
|