Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,24 @@
|
|
1 |
-
import openai
|
2 |
import gradio as gr
|
3 |
-
import
|
4 |
-
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
model="llama3-8b-8192", # Replace with your desired model
|
23 |
-
messages=conversation_history
|
24 |
-
)
|
25 |
-
bot_reply = response.choices[0].message.content
|
26 |
-
conversation_history.append({"role": "assistant", "content": bot_reply})
|
27 |
-
return bot_reply
|
28 |
-
except Exception as e:
|
29 |
-
return f"Error: {e}"
|
30 |
-
|
31 |
-
# Create Gradio interface
|
32 |
-
chatbot_ui = gr.Interface(
|
33 |
-
fn=chat_with_groq,
|
34 |
-
inputs=gr.Textbox(lines=2, placeholder="Type your message..."),
|
35 |
-
outputs=gr.Textbox(),
|
36 |
-
title="Groq Chatbot",
|
37 |
-
description="Chat with an AI powered by Groq API!"
|
38 |
)
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
-
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the translation pipeline
|
5 |
+
translator = pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")
|
6 |
+
|
7 |
+
def translate_text(text):
|
8 |
+
if not text.strip():
|
9 |
+
return "Please enter some text."
|
10 |
+
|
11 |
+
translated = translator(text)
|
12 |
+
return translated[0]['translation_text']
|
13 |
+
|
14 |
+
# Gradio Interface
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=translate_text,
|
17 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter text in English..."),
|
18 |
+
outputs=gr.Textbox(label="Translated Text in Urdu"),
|
19 |
+
title="English to Urdu Translator",
|
20 |
+
description="Enter English text and get its Urdu translation instantly."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
)
|
22 |
|
23 |
if __name__ == "__main__":
|
24 |
+
iface.launch()
|