Spaces:
Runtime error
Runtime error
File size: 2,310 Bytes
c714579 0f8bde0 c714579 93cfa6a 348670d 230bfc9 6a499ee 230bfc9 6a499ee 4f47f17 f6e0289 348670d d846673 4f47f17 e42c0ff 348670d 2394fb5 4f47f17 e42c0ff 6a499ee 230bfc9 ec5fa3e 230bfc9 46167bc 230bfc9 6a499ee 46167bc 6a499ee ec5fa3e 230bfc9 6a499ee 5462aaf 2565735 746c902 2565735 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import os
import gradio as gr
from huggingface_hub import InferenceClient
api_key = os.getenv("HF_API_KEY")
client = InferenceClient(api_key=api_key)
# Create shared state for the textbox values
class State:
def __init__(self):
self.context = "This Adrega component is designed to answer questions provided by API"
self.question = "What does this component do?"
state = State()
'''def analyze(project_data, question):
try:
prompt = f"Analyze this project: {project_data}\n\nQuestion: {question}"
messages = [
{"role": "system", "content": f"Context: {project_data}"},
{"role": "user", "content": question}
]
response = client.chat.completions.create(
model="Qwen/Qwen2.5-72B-Instruct",
messages=messages,
max_tokens=1000,
stream=True
)
answer = ""
for chunk in response:
answer += chunk['choices'][0]['delta']['content']
yield answer
except Exception as e:
print(f"Error details: {str(e)}")
yield f"Error occurred: {str(e)}"
'''
# Function to update textbox values
def update_values(context, question):
state.context = context
state.question = question
return state.context
with gr.Blocks() as iface:
# Create the components with the state values
project_data = gr.Textbox(label="Project Data", lines=2, value=lambda: state.context)
question = gr.Textbox(label="Question", lines=1, value=lambda: state.question)
output = gr.Textbox(label="Output")
# Create analyze button
#analyze_btn = gr.Button("Analyze")
# Connect the analyze function
#analyze_btn.click(
# fn=analyze,
# inputs=[project_data, question],
# outputs=output
#)
update_btn = gr.Button("Update")
update_btn.click(
fn=update_values,
inputs=['test1', 'test2'],
outputs=output
)
# Add API endpoint for updating values
iface.add_api_route("/update_values", update_values, methods=["POST"])
# Configure for external access
iface.launch(
server_name="0.0.0.0", # Allow external connections
share=True, # Create public URL
allowed_paths=["*"], # Allow CORS
)
|