riyans98 commited on
Commit
0224a63
·
verified ·
1 Parent(s): 63c07e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -0
app.py CHANGED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from huggingface_hub import InferenceClient
4
+
5
+
6
+ def respond(
7
+ message,
8
+ history: list[dict[str, str]],
9
+ system_message,
10
+ max_tokens,
11
+ temperature,
12
+ top_p,
13
+ hf_token: gr.OAuthToken,
14
+ ):
15
+ """
16
+ For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
17
+ """
18
+ client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
19
+
20
+ messages = [{"role": "system", "content": system_message}]
21
+
22
+ messages.extend(history)
23
+
24
+ messages.append({"role": "user", "content": message})
25
+
26
+ response = ""
27
+
28
+ for message in client.chat_completion(
29
+ messages,
30
+ max_tokens=max_tokens,
31
+ stream=True,
32
+ temperature=temperature,
33
+ top_p=top_p,
34
+ ):
35
+ choices = message.choices
36
+ token = ""
37
+ if len(choices) and choices[0].delta.content:
38
+ token = choices[0].delta.content
39
+
40
+ response += token
41
+ yield response
42
+
43
+ from transformers import VitsModel, AutoTokenizer
44
+ import torch
45
+
46
+ model = VitsModel.from_pretrained("facebook/mms-tts-hne")
47
+ tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-hne")
48
+
49
+ text =
50
+ inputs = tokenizer(text, return_tensors="pt")
51
+
52
+ with torch.no_grad():
53
+ output = model(**inputs).waveform
54
+
55
+ """
56
+ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
57
+ """
58
+ chatbot = gr.ChatInterface(
59
+ respond,
60
+ type="messages",
61
+ additional_inputs=[
62
+ gr.Textbox(value="You are a friendly Chhattishgarhi Chatbot.", label="System message"),
63
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
64
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
65
+ gr.Slider(
66
+ minimum=0.1,
67
+ maximum=1.0,
68
+ value=0.95,
69
+ step=0.05,
70
+ label="Top-p (nucleus sampling)",
71
+ ),
72
+ ],
73
+ )
74
+
75
+ with gr.Blocks() as demo:
76
+ with gr.Sidebar():
77
+ gr.LoginButton()
78
+ chatbot.render()
79
+
80
+
81
+ if __name__ == "__main__":
82
+ demo.launch()
83
+