RajuKandasamy commited on
Commit
500d34c
1 Parent(s): e2d01ec

Upload 3 files

Browse files

Initial Draft commit

Files changed (3) hide show
  1. README.md +4 -4
  2. app.py +72 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
  title: MarabuTamilDemo
3
- emoji: 🚀
4
- colorFrom: yellow
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 4.17.0
8
  app_file: app.py
9
  pinned: false
10
  license: gpl-3.0
 
1
  ---
2
  title: MarabuTamilDemo
3
+ emoji: 📉
4
+ colorFrom: green
5
+ colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 4.16.0
8
  app_file: app.py
9
  pinned: false
10
  license: gpl-3.0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
2
+ from threading import Thread
3
+ import gradio as gr
4
+
5
+ class ChatbotService:
6
+ def __init__(self, model_name="RajuKandasamy/marabutamil"):
7
+ self.model = AutoModelForCausalLM.from_pretrained(model_name)
8
+ self.tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+ self.streamer = None
10
+
11
+ def call(self, prompt):
12
+ self.streamer = TextIteratorStreamer(self.tokenizer, skip_prompt=True, timeout=5)
13
+ prompt = prompt.replace("<br>", "\n")
14
+ print(prompt)
15
+ inputs = self.tokenizer(prompt, return_tensors="pt")
16
+ print(inputs)
17
+ kwargs = dict(input_ids=inputs["input_ids"], streamer=self.streamer, max_new_tokens=256, do_sample=True, top_p=0.8, top_k=500, temperature=0.001, repetition_penalty=1.4)
18
+ thread = Thread(target=self.model.generate, kwargs=kwargs)
19
+ thread.start()
20
+ return ""
21
+
22
+
23
+ import gradio as gr
24
+
25
+ example_questions = [
26
+ f"""பாடல்:
27
+ நின்றன நின்றன நில்லாகும்""",
28
+ f"""செல்வம் நிலையாமை
29
+ அறத்துப்பால்
30
+ பாடல்:
31
+ துகள்தீர் பெருஞ்செல்வம் தோன்றியக்கால் தொட்டுப்""",
32
+ f"""பாடல்:
33
+ கொங்குதேர் வாழ்க்கை அஞ்சிறைத் தும்பி
34
+ காமம் செப்பாது கண்டது மொழிமோ""",
35
+ f"""வேதம் உரைத்தானும் வேதிய னாகிலன்
36
+ வேதம் உரைத்தானும் வேதா விளங்கிட"""
37
+ ]
38
+
39
+
40
+ chatbot_service = ChatbotService()
41
+
42
+
43
+ with gr.Blocks() as demo:
44
+ chatbot = gr.Chatbot()
45
+ with gr.Row():
46
+ msg = gr.Textbox(placeholder="Type your message here...", label="Venba first Stanza:")
47
+ run = gr.Button("Run")
48
+ examples_dropdown = gr.Dropdown(choices=example_questions, label="Select an example prompt")
49
+ examples_dropdown.change(fn=lambda x: x, inputs=examples_dropdown, outputs=msg)
50
+
51
+ clear = gr.Button("Clear")
52
+
53
+ def user(question, user_message, history):
54
+ if history == None:
55
+ history = []
56
+ user_message = question
57
+ return "", history + [[user_message, None]]
58
+
59
+ def bot(history):
60
+ #print("Question: ", history[-1][0])
61
+ chatbot_service.call(history[-1][0])
62
+ history[-1][1] = ""
63
+ for character in chatbot_service.streamer:
64
+ print(character)
65
+ history[-1][1] += character
66
+ yield history
67
+
68
+ run.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(bot, chatbot, chatbot)
69
+ clear.click(lambda: None, None, chatbot, queue=False)
70
+
71
+ demo.queue()
72
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ gradio==3.37.0
3
+ transformers==4.37.1