Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
-
|
4 |
-
model_id = "alibidaran/Gemma2_Farsi"
|
5 |
-
|
6 |
-
|
7 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
8 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, device_map='cpu')
|
9 |
-
model = model.to("cpu")
|
10 |
-
|
11 |
-
def generate_response(prompt):
|
12 |
-
text = f"<s> ###Human: {prompt} ###Assistant: "
|
13 |
-
inputs = tokenizer(text, return_tensors='pt').to('cpu')
|
14 |
-
|
15 |
-
outputs = model.generate(
|
16 |
-
**inputs,
|
17 |
-
max_new_tokens=512,
|
18 |
-
do_sample=True,
|
19 |
-
top_p=0.9,
|
20 |
-
top_k=50,
|
21 |
-
temperature=0.7,
|
22 |
-
output_scores=True,
|
23 |
-
return_dict_in_generate=True
|
24 |
-
)
|
25 |
-
|
26 |
-
response = tokenizer.decode(outputs['sequences'][0], skip_special_tokens=True)
|
27 |
-
return response
|
28 |
-
|
29 |
-
with gr.Blocks(theme=gr.themes.Base(), css=".gr-block {background-color: #f7f7f7; border-radius: 10px;}") as demo:
|
30 |
-
gr.Markdown("## مدل زبانی فارسی ")
|
31 |
-
|
32 |
-
with gr.Row():
|
33 |
-
with gr.Column(scale=1):
|
34 |
-
user_input = gr.Textbox(label="Enter your question in Farsi", placeholder="یه چی بگو", lines=3)
|
35 |
-
with gr.Column(scale=1):
|
36 |
-
response_output = gr.Textbox(label="جواب ", lines=10)
|
37 |
-
|
38 |
-
generate_button = gr.Button("جواب بده")
|
39 |
-
|
40 |
-
generate_button.click(fn=generate_response, inputs=user_input, outputs=response_output)
|
41 |
-
|
42 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|