Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,25 @@
|
|
| 1 |
-
from huggingface_hub import
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
client =
|
| 6 |
|
| 7 |
def translate_text(input_text, target_language):
|
| 8 |
prompt = f"Translate the following text into {target_language}: {input_text}"
|
| 9 |
try:
|
| 10 |
-
|
| 11 |
-
#
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
except Exception as e:
|
| 14 |
translated_text = f"Error: {str(e)}"
|
| 15 |
return translated_text
|
| 16 |
|
| 17 |
iface = gr.Interface(
|
| 18 |
fn=translate_text,
|
| 19 |
-
inputs=[
|
| 20 |
-
gr.Textbox(label="Text to Translate", placeholder="Enter the text you want to translate here..."),
|
| 21 |
-
gr.Textbox(label="Target Language", placeholder="Enter the target language (e.g., French, Spanish)..."),
|
| 22 |
-
],
|
| 23 |
outputs=gr.Textbox(label="Translated Text"),
|
| 24 |
title="Simple Translator with Mixtral",
|
| 25 |
description="Translate text to your specified language using the Mixtral model from Hugging Face."
|
|
|
|
| 1 |
+
from huggingface_hub import InferenceApi
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Note: Replace "your_hugging_face_api_key" with your actual API key.
|
| 5 |
+
client = InferenceApi("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 6 |
|
| 7 |
def translate_text(input_text, target_language):
|
| 8 |
prompt = f"Translate the following text into {target_language}: {input_text}"
|
| 9 |
try:
|
| 10 |
+
# Adjusted to use a hypothetical 'generate' or similar method.
|
| 11 |
+
# You'll need to replace this with the actual method for sending inference requests.
|
| 12 |
+
response = client.generate(inputs=prompt)
|
| 13 |
+
# The response structure depends on the model and the API's current design.
|
| 14 |
+
# You may need to adjust how you extract the translated text from the response.
|
| 15 |
+
translated_text = response['generated_text'] if 'generated_text' in response else "Translation error or model response format has changed."
|
| 16 |
except Exception as e:
|
| 17 |
translated_text = f"Error: {str(e)}"
|
| 18 |
return translated_text
|
| 19 |
|
| 20 |
iface = gr.Interface(
|
| 21 |
fn=translate_text,
|
| 22 |
+
inputs=[gr.Textbox(label="Text to Translate"), gr.Textbox(label="Target Language")],
|
|
|
|
|
|
|
|
|
|
| 23 |
outputs=gr.Textbox(label="Translated Text"),
|
| 24 |
title="Simple Translator with Mixtral",
|
| 25 |
description="Translate text to your specified language using the Mixtral model from Hugging Face."
|