Bofandra commited on
Commit
d00ad25
·
verified ·
1 Parent(s): 3a68b34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -1,10 +1,9 @@
1
- import gradio as gr
2
- from text_generation import InferenceAPIClient
3
  import os
 
 
4
 
5
- # ✅ Choose your model (you can change this to another instruct model)
6
- # client = InferenceAPIClient("deepseek-ai/DeepSeek-R1-0528", token=os.getenv("HF_TOKEN"))
7
- client = InferenceAPIClient("bigscience/bloomz")
8
 
9
  # 🧠 Function to generate software architecture
10
  def generate_software_spec(name, description, architecture, components, deployment, platform, extra):
@@ -49,17 +48,16 @@ Return the result in this format:
49
  ```
50
  """
51
 
52
- # Token Streaming
53
- text = ""
54
- for response in client.generate_stream(prompt):
55
- if not response.token.special:
56
- text += response.token.text
57
- return text
58
- # Generate from model (stream=True recommended for large output)
59
- #result = ""
60
- #for chunk in client.text_generation(prompt, stream=True, max_new_tokens=1024, temperature=0.7, stop=["</s>"]):
61
- # result += chunk.token.text
62
- #return result
63
 
64
  # 🎨 Gradio UI
65
  with gr.Blocks() as demo:
 
 
 
1
  import os
2
+ import gradio as gr
3
+ from huggingface_hub import InferenceClient
4
 
5
+ # ✅ Set up Hugging Face client with token from environment
6
+ llm = InferenceClient(token=os.getenv("HF_TOKEN"))
 
7
 
8
  # 🧠 Function to generate software architecture
9
  def generate_software_spec(name, description, architecture, components, deployment, platform, extra):
 
48
  ```
49
  """
50
 
51
+ # Generate response from Hugging Face Inference Client
52
+ response = llm.chat_completion(
53
+ messages=[
54
+ {"role": "system", "content": "You are a helpful software architecture assistant."},
55
+ {"role": "user", "content": prompt}
56
+ ],
57
+ model="deepseek-ai/DeepSeek-R1-0528",
58
+ max_tokens=2048,
59
+ )
60
+ return response.choices[0].message["content"] if response and response.choices else "Error: No response received."
 
61
 
62
  # 🎨 Gradio UI
63
  with gr.Blocks() as demo: