Hira99 commited on
Commit
35b65d3
1 Parent(s): 642500f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -1,28 +1,28 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Load the conversational model
5
- def load_chat_model():
6
- return pipeline("text-generation", model="microsoft/DialoGPT-medium")
 
7
 
8
- chat_model = load_chat_model()
9
-
10
- # Define the chat function
11
- def chat_with_bot(user_input):
12
- # Generate response from the chatbot model
13
- response = chat_model(user_input, max_length=100, num_return_sequences=1)
14
- return response[0]['generated_text']
 
15
 
16
  # Create the Gradio interface
17
  iface = gr.Interface(
18
- fn=chat_with_bot,
19
- inputs=gr.Textbox(label="You:", placeholder="Type your message here..."),
20
- outputs=gr.Textbox(label="Bot:"),
21
- title="English Learning Chatbot",
22
- description="Talk to the chatbot to practice English.",
23
- theme="default"
24
  )
25
 
26
  # Launch the app
27
- if __name__ == "__main__":
28
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import MBart50TokenizerFast, MBartForConditionalGeneration
3
 
4
+ # Load the fine-tuned model
5
+ model_name = "abdulwaheed1/urdu_to_english_translation_mbart"
6
+ tokenizer = MBart50TokenizerFast.from_pretrained(model_name, src_lang="ur_PK", tgt_lang="en_XX")
7
+ model = MBartForConditionalGeneration.from_pretrained(model_name)
8
 
9
+ def translate_urdu_to_english(text):
10
+ # Tokenize the input text
11
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
12
+ # Generate translation
13
+ outputs = model.generate(**inputs)
14
+ # Decode the translated text
15
+ translation = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
16
+ return translation
17
 
18
  # Create the Gradio interface
19
  iface = gr.Interface(
20
+ fn=translate_urdu_to_english,
21
+ inputs=gr.inputs.Textbox(label="Input Urdu Text"),
22
+ outputs=gr.outputs.Textbox(label="Translated English Text"),
23
+ title="Urdu to English Translation",
24
+ description="Enter Urdu text to get the English translation."
 
25
  )
26
 
27
  # Launch the app
28
+ iface.launch()