Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,15 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from transformers import
|
| 4 |
from deep_translator import GoogleTranslator
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def generate_topics(field, major, keywords, audience, level):
|
| 10 |
-
prompt = f"""
|
| 11 |
-
Suggest 3 academic thesis topics based on the following information:
|
| 12 |
Field: {field}
|
| 13 |
Specialization: {major}
|
| 14 |
Keywords: {keywords}
|
|
@@ -16,7 +17,11 @@ Target audience: {audience}
|
|
| 16 |
Level: {level}
|
| 17 |
"""
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
translated_output = GoogleTranslator(source='en', target='fa').translate(english_output)
|
| 21 |
|
| 22 |
final_output = translated_output.strip() + "\n\n📢 برای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:\n02188252497"
|
|
@@ -35,4 +40,4 @@ iface = gr.Interface(
|
|
| 35 |
title="🎓 پیشنهادگر موضوع پایاننامه کاسپین"
|
| 36 |
)
|
| 37 |
|
| 38 |
-
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, Gemma3ForConditionalGeneration
|
| 3 |
from deep_translator import GoogleTranslator
|
| 4 |
+
import torch
|
| 5 |
|
| 6 |
+
# بارگذاری توکنایزر و مدل
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-3-4b-it")
|
| 8 |
+
model = Gemma3ForConditionalGeneration.from_pretrained("google/gemma-3-4b-it", torch_dtype=torch.bfloat16)
|
| 9 |
+
model.eval()
|
| 10 |
|
| 11 |
def generate_topics(field, major, keywords, audience, level):
|
| 12 |
+
prompt = f"""Suggest 3 academic thesis topics based on the following information:
|
|
|
|
| 13 |
Field: {field}
|
| 14 |
Specialization: {major}
|
| 15 |
Keywords: {keywords}
|
|
|
|
| 17 |
Level: {level}
|
| 18 |
"""
|
| 19 |
|
| 20 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 21 |
+
with torch.no_grad():
|
| 22 |
+
outputs = model.generate(**inputs, max_new_tokens=256)
|
| 23 |
+
english_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 24 |
+
|
| 25 |
translated_output = GoogleTranslator(source='en', target='fa').translate(english_output)
|
| 26 |
|
| 27 |
final_output = translated_output.strip() + "\n\n📢 برای مشاوره و راهنمایی تخصصی با گروه مشاوره کاسپین تماس بگیرید:\n02188252497"
|
|
|
|
| 40 |
title="🎓 پیشنهادگر موضوع پایاننامه کاسپین"
|
| 41 |
)
|
| 42 |
|
| 43 |
+
iface.launch()
|