sachin commited on
Commit
8a2f4e9
·
1 Parent(s): f47e891
Files changed (2) hide show
  1. app.py +52 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import dwani
4
+ import os
5
+
6
+ dwani.api_key = os.getenv("DWANI_API_KEY")
7
+ dwani.api_base = os.getenv("DWANI_API_BASE_URL")
8
+
9
+ def chat_api(prompt, language, tgt_language):
10
+ resp = dwani.Chat.create(prompt, language, tgt_language)
11
+ return resp
12
+
13
+ # Language options as simple array
14
+ language_options = ["English", "Kannada", "Hindi"]
15
+
16
+ # Create Gradio interface
17
+ with gr.Blocks(title="Chat API Interface") as demo:
18
+ gr.Markdown("# Chat API Interface")
19
+
20
+ with gr.Row():
21
+ with gr.Column():
22
+ # Input components
23
+ prompt_input = gr.Textbox(
24
+ label="Prompt",
25
+ placeholder="Enter your prompt here (e.g., 'hi')"
26
+ )
27
+ language_input = gr.Dropdown(
28
+ label="Source Language",
29
+ choices=language_options,
30
+ value="English"
31
+ )
32
+ tgt_language_input = gr.Dropdown(
33
+ label="Target Language",
34
+ choices=language_options,
35
+ value="Kannada"
36
+ )
37
+
38
+ submit_btn = gr.Button("Submit")
39
+
40
+ with gr.Column():
41
+ # Output component
42
+ output = gr.JSON(label="Response")
43
+
44
+ # Connect the button click to the API function
45
+ submit_btn.click(
46
+ fn=chat_api,
47
+ inputs=[prompt_input, language_input, tgt_language_input],
48
+ outputs=output
49
+ )
50
+
51
+ # Launch the interface
52
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ dwani