TejAndrewsACC commited on
Commit
79029a7
·
verified ·
1 Parent(s): 5428518

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -38
app.py CHANGED
@@ -1634,8 +1634,8 @@ print("Transformer Output:", transformer_output)
1634
 
1635
 
1636
 
1637
- import gradio as gr
1638
- from openai import OpenAI
1639
 
1640
  hf_token = os.getenv("HF_TOKEN")
1641
 
@@ -1645,44 +1645,45 @@ SYSTEM_PROMPT = os.getenv("SYSTEM_PROMPT")
1645
  print(SYSTEM_PROMPT)
1646
 
1647
  # Initialize client
1648
- client = OpenAI(
1649
- base_url="https://router.huggingface.co/together/v1",
1650
- api_key=hf_token
1651
- )
1652
-
1653
- def predict(message, history):
1654
- # If history is empty, insert the system prompt
1655
- if not any(msg["role"] == "system" for msg in history):
1656
- history.insert(0, {"role": "system", "content": SYSTEM_PROMPT})
1657
-
1658
- history.append({"role": "user", "content": message})
1659
-
1660
- stream = client.chat.completions.create(
1661
- messages=history,
1662
- model=os.getenv("ACCEMULECTPLUS"),
1663
- stream=True
1664
- )
1665
-
1666
- chunks = []
1667
- for chunk in stream:
1668
- chunks.append(chunk.choices[0].delta.content or "")
1669
- yield "".join(chunks)
 
 
1670
 
1671
  demo = gr.ChatInterface(
1672
- fn=predict,
1673
- type="messages",
1674
- chatbot=gr.Chatbot(
1675
- type="messages",
1676
- label="💙ACC Emulect+💙",
1677
- avatar_images=(
1678
- "https://huggingface.co/spaces/TejAndrewsACC/Z3ta_Z/resolve/main/Screenshot_20250201-131420.png",
1679
- "https://huggingface.co/spaces/TejAndrewsACC/ACC-Emulect-Plus/resolve/main/IMG_1433.jpeg"
1680
- ),
1681
- placeholder="💙Hi, I'm ACC Emulect+💙",
1682
- ),
1683
- theme="TejAndrewsACC/Emulect",
1684
  )
1685
 
1686
  if __name__ == "__main__":
1687
- demo.launch(share=True)
1688
-
 
1634
 
1635
 
1636
 
1637
+ import gradio as gr
1638
+ from openai import OpenAI
1639
 
1640
  hf_token = os.getenv("HF_TOKEN")
1641
 
 
1645
  print(SYSTEM_PROMPT)
1646
 
1647
  # Initialize client
1648
+ client = OpenAI(
1649
+ base_url="https://router.huggingface.co/together/v1",
1650
+ api_key=hf_token
1651
+ )
1652
+
1653
+ def predict(message, history):
1654
+ # If history is empty, insert the system prompt
1655
+ if not any(msg["role"] == "system" for msg in history):
1656
+ history.insert(0, {"role": "system", "content": SYSTEM_PROMPT})
1657
+
1658
+ history.append({"role": "user", "content": message})
1659
+
1660
+ stream = client.chat.completions.create(
1661
+ messages=history,
1662
+ model=os.getenv("ACCEMULECTPLUS"),
1663
+ stream=True
1664
+ )
1665
+
1666
+ chunks = []
1667
+ for chunk in stream:
1668
+ if not chunk.choices:
1669
+ continue
1670
+ chunks.append(chunk.choices[0].delta.content or "")
1671
+ yield "".join(chunks)
1672
 
1673
  demo = gr.ChatInterface(
1674
+ fn=predict,
1675
+ type="messages",
1676
+ chatbot=gr.Chatbot(
1677
+ type="messages",
1678
+ label="💙ACC Emulect+💙",
1679
+ avatar_images=(
1680
+ "https://huggingface.co/spaces/TejAndrewsACC/Z3ta_Z/resolve/main/Screenshot_20250201-131420.png",
1681
+ "https://huggingface.co/spaces/TejAndrewsACC/ACC-Emulect-Plus/resolve/main/IMG_1433.jpeg"
1682
+ ),
1683
+ placeholder="💙Hi, I'm ACC Emulect+💙",
1684
+ ),
1685
+ theme="TejAndrewsACC/Emulect",
1686
  )
1687
 
1688
  if __name__ == "__main__":
1689
+ demo.launch(share=True)