on1onmangoes commited on
Commit
1d6a862
1 Parent(s): fdb554b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +108 -17
app.py CHANGED
@@ -1,16 +1,60 @@
1
  import gradio as gr
 
 
2
 
3
- # Define a function for the main application
4
- def greet(name):
5
- return f"Hello {name}!"
6
 
7
- # Define a function for the authentication
 
 
 
8
  def login(username, password):
9
- if username == "your_username" and password == "your_password":
10
  return True
11
  else:
12
  return False
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Create the Gradio Blocks interface
15
  with gr.Blocks() as app:
16
  gr.Markdown("### Login")
@@ -19,20 +63,67 @@ with gr.Blocks() as app:
19
  username_input = gr.Textbox(label="Username", placeholder="Enter your username")
20
  password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
21
 
22
- login_button = gr.Button("Login")
 
 
 
 
 
 
23
  output_text = gr.Textbox(label="Output", interactive=False)
24
 
25
- # Function to handle login and display greeting
26
- def handle_login(username, password):
27
- if login(username, password):
28
- # Clear the password field and display the greeting
29
- #password_input.clear()
30
- return greet(username)
31
- else:
32
- return "Invalid credentials! Please try again."
33
-
34
- # Bind the button click to the handle_login function
35
- login_button.click(handle_login, inputs=[username_input, password_input], outputs=output_text)
36
 
37
  # Launch the app
38
  app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from gradio_client import Client, handle_file
3
+ import os
4
 
5
+ # Define your Hugging Face token (make sure to set it as an environment variable)
6
+ HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using env variable
 
7
 
8
+ # Initialize the Gradio Client for the specified API
9
+ client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
10
+
11
+ # Authentication function
12
  def login(username, password):
13
+ if username == "your_username" and password == "your_password": # Update with actual credentials
14
  return True
15
  else:
16
  return False
17
 
18
+ # Function to handle different API calls based on user input
19
+ def handle_api_call(username, password, audio_file=None, pdf_file=None, message=None, query=None, question=None):
20
+ if not login(username, password):
21
+ return "Invalid credentials! Please try again."
22
+
23
+ if audio_file:
24
+ # Handle audio file using the appropriate API
25
+ result = client.predict(audio=handle_file(audio_file), api_name="/process_audio") # Example endpoint for audio processing
26
+ return result
27
+ elif pdf_file:
28
+ # Handle PDF file
29
+ pdf_result = client.predict(pdf_file=handle_file(pdf_file), client_name="rosariarossi", api_name="/process_pdf2")
30
+ return pdf_result[1] # Returning the string result from the PDF processing
31
+ elif message:
32
+ # Handle chat message
33
+ chat_result = client.predict(
34
+ message=message,
35
+ client_name="rosariarossi",
36
+ system_prompt="You are an expert assistant",
37
+ num_retrieved_docs=10,
38
+ num_docs_final=9,
39
+ temperature=0,
40
+ max_new_tokens=1024,
41
+ top_p=1,
42
+ top_k=20,
43
+ penalty=1.2,
44
+ api_name="/chat"
45
+ )
46
+ return chat_result
47
+ elif query:
48
+ # Handle search query
49
+ search_result = client.predict(query=query, api_name="/search_with_confidence")
50
+ return search_result
51
+ elif question:
52
+ # Handle question for RAG
53
+ rag_result = client.predict(question=question, api_name="/answer_with_rag")
54
+ return rag_result
55
+ else:
56
+ return "No valid input provided!"
57
+
58
  # Create the Gradio Blocks interface
59
  with gr.Blocks() as app:
60
  gr.Markdown("### Login")
 
63
  username_input = gr.Textbox(label="Username", placeholder="Enter your username")
64
  password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
65
 
66
+ audio_input = gr.Audio(label="Upload Audio File", type="filepath")
67
+ pdf_input = gr.File(label="Upload PDF File")
68
+
69
+ message_input = gr.Textbox(label="Enter Message for Chat")
70
+ query_input = gr.Textbox(label="Enter Search Query")
71
+ question_input = gr.Textbox(label="Enter Question for RAG")
72
+
73
  output_text = gr.Textbox(label="Output", interactive=False)
74
 
75
+ # Bind the button click to the handle_api_call function
76
+ api_button = gr.Button("Submit")
77
+ api_button.click(
78
+ handle_api_call,
79
+ inputs=[username_input, password_input, audio_input, pdf_input, message_input, query_input, question_input],
80
+ outputs=output_text
81
+ )
 
 
 
 
82
 
83
  # Launch the app
84
  app.launch()
85
+
86
+
87
+
88
+
89
+
90
+ # import gradio as gr
91
+
92
+ # # Define a function for the main application
93
+ # def greet(name):
94
+ # return f"Hello {name}!"
95
+
96
+ # # Define a function for the authentication
97
+ # def login(username, password):
98
+ # if username == "your_username" and password == "your_password":
99
+ # return True
100
+ # else:
101
+ # return False
102
+
103
+ # # Create the Gradio Blocks interface
104
+ # with gr.Blocks() as app:
105
+ # gr.Markdown("### Login")
106
+
107
+ # with gr.Row():
108
+ # username_input = gr.Textbox(label="Username", placeholder="Enter your username")
109
+ # password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
110
+
111
+ # login_button = gr.Button("Login")
112
+ # output_text = gr.Textbox(label="Output", interactive=False)
113
+
114
+ # # Function to handle login and display greeting
115
+ # def handle_login(username, password):
116
+ # if login(username, password):
117
+ # # Clear the password field and display the greeting
118
+ # #password_input.clear()
119
+ # return greet(username)
120
+ # else:
121
+ # return "Invalid credentials! Please try again."
122
+
123
+ # # Bind the button click to the handle_login function
124
+ # login_button.click(handle_login, inputs=[username_input, password_input], outputs=output_text)
125
+
126
+ # # Launch the app
127
+ # app.launch()
128
+
129
+