aquibmoin commited on
Commit
7e6c312
·
verified ·
1 Parent(s): 8760cb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -20
app.py CHANGED
@@ -5,36 +5,33 @@ import requests
5
  API_URL = "https://api-inference.huggingface.co/models/nasa-impact/nasa-smd-ibm-v0.1"
6
  headers = {"Authorization": "Bearer HF_TOKEN"}
7
 
8
- def query_huggingface(payload):
9
- response = requests.post(API_URL, headers=headers, json=payload)
10
- return response.json()
11
-
12
- # Function to generate response
13
- def generate_response(user_message):
14
  payload = {
15
- "inputs": user_message
16
  }
 
 
17
 
18
- response = query_huggingface(payload)
 
 
19
  output = response.get('generated_text', 'No response') # Adjust according to the model's response format
20
-
21
  return output
22
 
23
  # Gradio interface
24
- def gradio_interface(user_message, history):
25
- response = generate_response(user_message)
26
- history.append((user_message, response))
27
- return history, history
28
 
29
  # Define Gradio blocks
30
- with gr.Blocks() as demo:
31
- user_message = gr.Textbox(label="Your Message")
32
- chatbot = gr.Chatbot(label="Chat History")
33
- state = gr.State([])
34
- submit_button = gr.Button("Submit")
35
-
36
- submit_button.click(gradio_interface, inputs=[user_message, state], outputs=[chatbot, state])
37
 
38
  # Launch the interface
39
  demo.launch()
40
 
 
 
5
  API_URL = "https://api-inference.huggingface.co/models/nasa-impact/nasa-smd-ibm-v0.1"
6
  headers = {"Authorization": "Bearer HF_TOKEN"}
7
 
8
+ def query_huggingface():
 
 
 
 
 
9
  payload = {
10
+ "inputs": "The answer to the universe is <mask>."
11
  }
12
+ response = requests.post(API_URL, headers=headers, json=payload)
13
+ return response.json()
14
 
15
+ def get_model_output():
16
+ response = query_huggingface()
17
+ # Extract the output from the response
18
  output = response.get('generated_text', 'No response') # Adjust according to the model's response format
 
19
  return output
20
 
21
  # Gradio interface
22
+ def gradio_interface():
23
+ return get_model_output()
 
 
24
 
25
  # Define Gradio blocks
26
+ demo = gr.Interface(
27
+ fn=gradio_interface,
28
+ inputs=[],
29
+ outputs="text",
30
+ title="Hugging Face Model Output",
31
+ description="Feed a hard-coded input to the model and get the output."
32
+ )
33
 
34
  # Launch the interface
35
  demo.launch()
36
 
37
+