Naz786 commited on
Commit
f1b7a55
·
verified ·
1 Parent(s): b2de99e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -37
app.py CHANGED
@@ -1,41 +1,24 @@
1
- import openai
2
  import gradio as gr
3
- import os
4
-
5
- # Set up Groq API key
6
- GROQ_API_KEY = "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" # Use environment variable for security
7
- client = openai.OpenAI(api_key=GROQ_API_KEY, base_url="https://api.groq.com/openai/v1")
8
-
9
- # Initialize conversation history
10
- conversation_history = []
11
-
12
- def chat_with_groq(user_input):
13
- global conversation_history
14
-
15
- if user_input.lower() == 'exit':
16
- return "Chatbot: Goodbye!"
17
-
18
- conversation_history.append({"role": "user", "content": user_input})
19
-
20
- try:
21
- response = client.chat.completions.create(
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
- chatbot_ui.launch(share=True)
 
 
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()