Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
| 3 |
|
|
@@ -15,8 +16,15 @@ def format_prompt(message, history):
|
|
| 15 |
return prompt
|
| 16 |
|
| 17 |
def generate(
|
| 18 |
-
prompt, history, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
| 19 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
temperature = float(temperature)
|
| 21 |
if temperature < 1e-2:
|
| 22 |
temperature = 1e-2
|
|
@@ -38,10 +46,16 @@ def generate(
|
|
| 38 |
for response in stream:
|
| 39 |
output += response.token.text
|
| 40 |
yield output
|
|
|
|
|
|
|
| 41 |
return output
|
| 42 |
|
| 43 |
|
| 44 |
additional_inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
gr.Textbox(
|
| 46 |
label="System Prompt",
|
| 47 |
max_lines=1,
|
|
@@ -85,19 +99,9 @@ additional_inputs=[
|
|
| 85 |
)
|
| 86 |
]
|
| 87 |
|
| 88 |
-
examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, ],
|
| 89 |
-
["Can you write a short story about a time-traveling detective who solves historical mysteries?", None, None, None, None, None,],
|
| 90 |
-
["I'm trying to learn French. Can you provide some common phrases that would be useful for a beginner, along with their pronunciations?", None, None, None, None, None,],
|
| 91 |
-
["I have chicken, rice, and bell peppers in my kitchen. Can you suggest an easy recipe I can make with these ingredients?", None, None, None, None, None,],
|
| 92 |
-
["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None,],
|
| 93 |
-
["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
|
| 94 |
-
]
|
| 95 |
-
|
| 96 |
gr.ChatInterface(
|
| 97 |
fn=generate,
|
| 98 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
| 99 |
additional_inputs=additional_inputs,
|
| 100 |
-
title="Mixtral 46.7B",
|
| 101 |
-
examples=examples,
|
| 102 |
concurrency_limit=20,
|
| 103 |
-
).launch(
|
|
|
|
| 1 |
+
from deep_translator import GoogleTranslator
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
| 16 |
return prompt
|
| 17 |
|
| 18 |
def generate(
|
| 19 |
+
prompt, history, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,translate_fa,
|
| 20 |
):
|
| 21 |
+
if(translate_fa == True):
|
| 22 |
+
if(len(prompt) > 2000):
|
| 23 |
+
translatedtext1 = GoogleTranslator(source='auto', target='en').translate(prompt[0:2000])
|
| 24 |
+
translatedtext2 = GoogleTranslator(source='auto', target='en').translate(prompt[2000:(len(prompt))])
|
| 25 |
+
prompt = translatedtext1 + translatedtext2
|
| 26 |
+
else:
|
| 27 |
+
prompt = GoogleTranslator(source='auto', target='en').translate(prompt)
|
| 28 |
temperature = float(temperature)
|
| 29 |
if temperature < 1e-2:
|
| 30 |
temperature = 1e-2
|
|
|
|
| 46 |
for response in stream:
|
| 47 |
output += response.token.text
|
| 48 |
yield output
|
| 49 |
+
if(translate_fa == True):
|
| 50 |
+
output = GoogleTranslator(source='auto', target='fa').translate(output)
|
| 51 |
return output
|
| 52 |
|
| 53 |
|
| 54 |
additional_inputs=[
|
| 55 |
+
translate_fa = gr.Checkbox(
|
| 56 |
+
label="Translate to Persian",
|
| 57 |
+
value=True
|
| 58 |
+
),
|
| 59 |
gr.Textbox(
|
| 60 |
label="System Prompt",
|
| 61 |
max_lines=1,
|
|
|
|
| 99 |
)
|
| 100 |
]
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
gr.ChatInterface(
|
| 103 |
fn=generate,
|
| 104 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
| 105 |
additional_inputs=additional_inputs,
|
|
|
|
|
|
|
| 106 |
concurrency_limit=20,
|
| 107 |
+
).launch()
|