Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoTokenizer,
|
|
|
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
"Summarize in Tamil": "summarize: ",
|
| 13 |
-
"Translate to English": "translate Tamil to English: "
|
| 14 |
-
}
|
| 15 |
-
prefix = prefix_map.get(task_type, "restore: ")
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
# Gradio Interface
|
| 24 |
iface = gr.Interface(
|
| 25 |
-
fn=
|
| 26 |
inputs=[
|
| 27 |
-
gr.Textbox(label="
|
| 28 |
-
gr.
|
| 29 |
-
label="Select Task")
|
| 30 |
],
|
| 31 |
-
outputs=gr.Textbox(label="Output"),
|
| 32 |
-
title="
|
| 33 |
-
description="Restores
|
| 34 |
)
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Load DeepSeek-R1 model
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-R1", trust_remote_code=True)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-R1", trust_remote_code=True)
|
|
|
|
| 8 |
|
| 9 |
+
# Device config
|
| 10 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
+
model.to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
def restore_tamil_text(prompt, uploaded_file=None):
|
| 14 |
+
context = ""
|
| 15 |
+
|
| 16 |
+
# If a file is uploaded, read its contents and use it for context
|
| 17 |
+
if uploaded_file:
|
| 18 |
+
file_bytes = uploaded_file.read()
|
| 19 |
+
context = file_bytes.decode("utf-8")
|
| 20 |
+
full_prompt = f"You are an expert in ancient Tamil. Use the document below to restore and expand the text.\n\nDocument:\n{context}\n\nTask:\n{prompt}"
|
| 21 |
+
else:
|
| 22 |
+
full_prompt = f"You are a Tamil literature historian. {prompt}"
|
| 23 |
+
|
| 24 |
+
inputs = tokenizer(full_prompt, return_tensors="pt").to(device)
|
| 25 |
+
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
|
| 26 |
+
output_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 27 |
+
|
| 28 |
+
return output_text.strip()
|
| 29 |
|
|
|
|
| 30 |
iface = gr.Interface(
|
| 31 |
+
fn=restore_tamil_text,
|
| 32 |
inputs=[
|
| 33 |
+
gr.Textbox(label="Your Prompt (e.g., Restore this ancient Tamil text...)", lines=6),
|
| 34 |
+
gr.File(label="Optional: Upload Ancient Tamil File (.txt)")
|
|
|
|
| 35 |
],
|
| 36 |
+
outputs=gr.Textbox(label="Restored Output"),
|
| 37 |
+
title="🧠 Ancient Tamil Literature AI Agent",
|
| 38 |
+
description="Hybrid AI using DeepSeek-R1 + optional file context. Restores and expands ancient Tamil literature using DeepSeek LLM."
|
| 39 |
)
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|