Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app (1).py +15 -0
- requirements (1).txt +6 -0
app (1).py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import RagTokenizer, RagRetriever, RagTokenForGeneration
|
| 4 |
+
|
| 5 |
+
tokenizer = RagTokenizer.from_pretrained("facebook/rag-token-base")
|
| 6 |
+
retriever = RagRetriever.from_pretrained("facebook/rag-token-base", index_name="exact", use_dummy_dataset=True)
|
| 7 |
+
model = RagTokenForGeneration.from_pretrained("facebook/rag-token-base", retriever=retriever)
|
| 8 |
+
|
| 9 |
+
def ask_medication(question):
|
| 10 |
+
input_ids = tokenizer(question, return_tensors="pt").input_ids
|
| 11 |
+
outputs = model.generate(input_ids)
|
| 12 |
+
return tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
| 13 |
+
|
| 14 |
+
demo = gr.Interface(fn=ask_medication, inputs="text", outputs="text", title="💊 Medication Assistant", description="Ask about common medications and their uses!")
|
| 15 |
+
demo.launch()
|
requirements (1).txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
transformers
|
| 3 |
+
torch
|
| 4 |
+
gradio
|
| 5 |
+
datasets
|
| 6 |
+
faiss-cpu
|